package com.youth.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.lang.reflect.InvocationTargetException;

/**
 * @ClassName CommonUtils
 * @Description: TODO
 * @Author yjwu
 * @Date 2020/1/16 16:00
 **/
public class CommonUtils {
    /**
     * @param clazz
     * @MethodName: objectToJavaBean
     * @Description: TODO Object 转换为JavaBean
     * @Param: * @param o
     * @Return: {@link T}
     * @Author: yjwu
     * @Date: 2020/1/17 14:46
     **/
    public static <T> T objectToJavaBean(Object o, Class<T> clazz) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        String s = JSONObject.toJSONString(o);
        //clazz.getDeclaredConstructor().newInstance();
        T bean = JSONObject.toJavaObject(JSON.parseObject(s), clazz);
        return bean;
    }
}


